<?php
/**
 * Core_Db
 *
 * @author naspeh
 * @version $Id: Exception.php 659 2008-06-15 11:34:26Z naspeh $ 
 */
class Core_Db
{
    /**
     * Singleton instance
     *
     * Marked only as protected to allow extension of the class. To extend,
     * simply override {@link getInstance()}.
     *
     * @var array
     */
    protected static $_instance = array();
    /**
     * Constructor
     *
     * Instantiate using {@link getInstance()}; front controller is a singleton
     * object.
     *
     * Instantiates the plugin broker.
     *
     * @return void
     */
    private function __construct()
    {
    }
    /**
     * Клон
     *
     */
    private function __clone()
    {
    }
    /**
     * Singleton instance
     *
     * @return Zend_Db_Adapter_Abstract
     */
    public static function getInstance($index = 'dbAdapter')
    {
        if (!isset(self::$_instance[$index])) {
            $db = Zend_Db::factory(Core_Config::get('database|' . $index, null, true)) ;
            $cache = Core_Cache::get('default');        
            Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
            
            self::$_instance[$index] = $db;
        }

        return self::$_instance[$index];
    }
}